#!/usr/bin/python
# -*- coding: utf-8 -*- 
#coding=utf-8

import re
import sys
import os
import fileinput
import select

#  管道 文件名 文件重定向 字符串 都支持，特别帅
#  python filterChinese.py -v < e3.sh
#  python filterChinese.py < e3.sh
#  python filterChinese.py e3.sh
#  python filterChinese.py e3.sh
#  python filterChinese.py '计算 从 fromnum 到 tonum 范围内的整数的 平方根，写入文件'
#  python filterChinese.py -v '计算 从 fromnum 到 tonum 范围内的整数的 平方根，写入文件'
#  cat e3.sh|python filterChinese.py -v
#  cat e3.sh|python filterChinese.py

def findChinese(str2FindChinese, printWhenMatch):
    res = re.findall(u"[\u4e00-\u9fa5]+", str2FindChinese.decode('utf8'))
    #res = re.findall(u"\d", text)
    if len(res) > 0 and printWhenMatch:
        print str2FindChinese
        #for r in res:
            #print r.encode('utf8')
    elif len(res)==0 and not printWhenMatch:
        print str2FindChinese
#end of def findChinese
        
# 从管道读取, 且不会阻塞
strsFromPipe=[]
if select.select([sys.stdin, ], [], [], 0.0)[0]:
    strsFromPipe = sys.stdin.readlines()

printMatch = True
inputStr=""

if len(sys.argv) >1:
    if str(sys.argv[1]) == "-v":
        printMatch = False
        if len(sys.argv) > 2:
            inputStr=str(sys.argv[2])
    else:
        inputStr=str(sys.argv[1])

if os.access(inputStr, os.F_OK) and os.access(inputStr, os.R_OK):
    for line in open(inputStr):
        findChinese(line, printMatch)
else:
    lines=inputStr.splitlines()
    for line in lines:
        findChinese(line, printMatch)

for line in strsFromPipe:
    findChinese(line, printMatch)